package com.woniuxy.provider;

import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

public class EmpDynamicSqlProvider {
    public String select(final String ename,final Double sal){
        String result=new SQL(){
            {
                SELECT("*");
                FROM("emp");
                StringBuilder sb=new StringBuilder();
                if (ename!=null&&!"".equals(ename)){
                    sb.append(" AND ename LIKE");
                    sb.append("'%");
                    sb.append(ename);
                    sb.append("%'");
                }
                if(sal!=null&&sal!=0.0){
                    sb.append(" AND sal>");
                    sb.append(sal);
                }
                if(!"".equals(sb.toString())){
                    WHERE(sb.toString().replaceFirst("AND",""));
                }
            }
        }.toString();
        return result;
    }
}
